package com.jinlong.common.api;

import com.jinlong.constants.BaseApiConstants;
import com.sun.xml.internal.rngom.parse.host.Base;

import java.util.HashMap;
import java.util.Map;

public class BaseApiService {

    public Map<String,Object> setResultError(String msg){
        return setResult(BaseApiConstants.HTTP_500_CODE,msg,null);
    }


    public Map<String,Object> setResultParameterError(String msg){
        return setResult(BaseApiConstants.HTTP_400_CODE,msg,null);
    }

    public Map<String,Object> setResultSuccess(){
        return setResult(BaseApiConstants.HTTP_200_CODE,BaseApiConstants.HTTP_SUCCESS_NAME,null);
    }


    public Map<String,Object> setResultSuccessData(Object data){
        return setResult(BaseApiConstants.HTTP_200_CODE,BaseApiConstants.HTTP_SUCCESS_NAME,data);
    }

    public Map<String,Object> setResultSuccess(String msg){
        return setResult(BaseApiConstants.HTTP_200_CODE,msg,null);
    }

    public Map<String,Object> setResult(Integer code,String msg,Object data){
        Map<String,Object>  map = new  HashMap<String, Object>();
        map.put(BaseApiConstants.HTTP_CODE_NAME,code);
        map.put(BaseApiConstants.HTTP_200_NAME,msg);
        if(data != null)
        map.put(BaseApiConstants.HTTP_DATA_NAME,data);
        return  map;
    }
}
